package org.blxt.maven;

/**
 * Java代码注释率统计结果
 */
public class CommentRateStatistics {
    private int totalFiles;
    private int totalLines;
    private int commentLines;
    private int codeLines;
    private int blankLines;
    private double commentRate;
    private double minCommentRate;
    private double minCommentMethodRate;
    private int countOk = 0;
    private int countFalse = 0;
    private int countMethod = 0;
    private int countMethodFalse = 0;

    public CommentRateStatistics() {
    }

    public CommentRateStatistics(int totalFiles, int totalLines, int commentLines, int codeLines, int blankLines) {
        this.totalFiles = totalFiles;
        this.totalLines = totalLines;
        this.commentLines = commentLines;
        this.codeLines = codeLines;
        this.blankLines = blankLines;
        this.commentRate = codeLines > 0 ? (double) commentLines / codeLines * 100 : 0.0;
    }

    public int getTotalFiles() {
        return totalFiles;
    }

    public void setTotalFiles(int totalFiles) {
        this.totalFiles = totalFiles;
    }

    public int getTotalLines() {
        return totalLines;
    }

    public void setTotalLines(int totalLines) {
        this.totalLines = totalLines;
    }

    public int getCommentLines() {
        return commentLines;
    }

    public void setCommentLines(int commentLines) {
        this.commentLines = commentLines;
    }

    public int getCodeLines() {
        return codeLines;
    }

    public void setCodeLines(int codeLines) {
        this.codeLines = codeLines;
    }

    public int getBlankLines() {
        return blankLines;
    }

    public void setBlankLines(int blankLines) {
        this.blankLines = blankLines;
    }

    public double getCommentRate() {
        return commentRate;
    }

    public void setCommentRate(double commentRate) {
        this.commentRate = commentRate;
    }

    public int getCountOk() {
        return countOk;
    }

    public void setCountOk(int countOk) {
        this.countOk = countOk;
    }

    public int getCountFalse() {
        return countFalse;
    }

    public void setCountFalse(int countFalse) {
        this.countFalse = countFalse;
    }

    public double getMinCommentRate() {
        return minCommentRate;
    }

    public void setMinCommentRate(double minCommentRate) {
        this.minCommentRate = minCommentRate;
    }

    public int getCountMethodFalse() {
        return countMethodFalse;
    }

    public void setCountMethodFalse(int countMethodFalse) {
        this.countMethodFalse = countMethodFalse;
    }

    public int getCountMethod() {
        return countMethod;
    }

    public void setCountMethod(int countMethod) {
        this.countMethod = countMethod;
    }

    public double getMinCommentMethodRate() {
        return minCommentMethodRate;
    }

    public void setMinCommentMethodRate(double minCommentMethodRate) {
        this.minCommentMethodRate = minCommentMethodRate;
    }

    public void addFile(int lines, int comments, int code, int blank) {
        this.totalFiles++;
        this.totalLines += lines;
        this.commentLines += comments;
        this.codeLines += code;
        this.blankLines += blank;
        this.commentRate = this.codeLines > 0 ? (double) this.commentLines / this.codeLines * 100 : 0.0;
    }

    @Override
    public String toString() {
        return """
                ## Java代码注释率统计报告:
                
                ------------------------
                |项目|数据|
                |:----:|:----:|
                |扫描文件数|  %d |
                |总行数|   %d|
                |注释行数|  %d |
                |代码行数|  %d |
                |空白行数|  %d |
                |当前注释率| %.2f%%|
                |最低注释率| %.2f%%|
                |方法最低注释率| %.2f%%|
                |达标文件数|  %d |
                |不达标文件数|  %d |
                ------------------------
                |项目|数据|
                |:----:|:----:|
                |达标方法数| %d|
                |不达标方法数| %d|
                ------------------------"""
                .formatted(
                        totalFiles, totalLines, commentLines, codeLines, blankLines, commentRate,
                        minCommentRate, minCommentMethodRate,
                        countOk, countFalse,
                        countMethod, countMethodFalse
                );

    }
}